﻿using Prism.Commands;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF.Core;
using WPF.Zero.Services;

namespace WPF.Zero.ViewModels
{
    public class MainViewModel : NavigateViewModel
    {
        private readonly INavigationMenuService menuService;
        private readonly IRegionManager region;
        private ObservableCollection<NavigationItem> navigationItems;

        public ObservableCollection<NavigationItem> NavigationItems
        {
            get { return navigationItems; }
            set { navigationItems = value; OnPropertyChanged(); }
        }

        public DelegateCommand<NavigationItem> NavigateCommand { get; private set; }

        public MainViewModel(INavigationMenuService menuService,IRegionManager region)
        {
            this.menuService = menuService;
            this.region = region;
            this.NavigationItems = menuService.GetNavigationItems();
            NavigateCommand = new DelegateCommand<NavigationItem>(Navigate);
        } 

        private void Navigate(NavigationItem item)
        {
            try
            {
                if (item == null)
                {
                    return;
                }
                region.Regions["MainRegion"].RequestNavigate(item.PageName, callback =>
                {
                    if ((bool)callback.Result)
                    {

                    }
                });
            }
            catch (Exception ex) { Console.WriteLine(ex); }


        }
    }
}
